package com.cqy.spring.cloud.feign;

import com.cqy.spring.cloud.vo.Cqy;
import com.cqy.spring.cloud.vo.Demo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@FeignClient(value = "sc-client", path = "/client",fallback = TestFeignFallBack.class)
public interface TestFeign {

    @PostMapping("/test")
    Map<String, Object> test(@RequestBody @Validated({Cqy.Hello.class}) Cqy cqy);

    /**
     * create demo
     *
     * @param demo
     * @return
     */
    @PostMapping(value = "/demo")
    Demo create(@RequestBody @Valid Demo demo);

    /**
     * update demo
     *
     * @param demo
     * @return
     */
    @PutMapping(value = "/demo")
    Demo update(@RequestBody @Valid Demo demo);

    /**
     * delete demo
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/demo/{id}")
    Demo delete(@PathVariable(name = "id") String id);

    /**
     * list demo
     *
     * @param id
     * @param headerValue test header value
     * @return
     */
    @GetMapping(value = "/demo/{id}")
    Demo get(@PathVariable(name = "id") String id, @RequestHeader(name = "header") String headerValue);

    /**
     * list demos
     *
     * @return
     */
    @GetMapping(value = "/demos")
    List<Demo> list();

    /**
     * upload file
     *
     * @param file
     * @return
     */
    @PostMapping(value = "/demo/upload", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String upload(@RequestPart(name = "file") MultipartFile file);

}
